package com.dats.util;


import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author sig
 * @since 2016/6/11
 */
public class TimeUtil {

    public static long parse(String pattern, String source) {
        Calendar calendar = Calendar.getInstance();

        try {
            calendar.setTime(new SimpleDateFormat(pattern).parse(source));
        } catch (Exception e) {
            LogUtil.console.error(e.getMessage(), e);
            return 0L;
        }
        return calendar.getTimeInMillis();
    }

    public static String format(String pattern, long millis) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(millis);
        return new SimpleDateFormat(pattern).format(calendar.getTime());
    }
}
